package com.bjesc_b2c.app.appraiset.mvp.view.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.adapter.MainViewAdapter;
import com.bjesc_b2c.app.appraiset.base.BaseFragment;
import com.bjesc_b2c.app.appraiset.bean.ItemViewBean;
import com.bjesc_b2c.app.appraiset.mvp.view.activity.RepulseHistoryActivity;
import com.bjesc_b2c.app.appraiset.mvp.view.activity.WaitCheckActivity;

import java.util.ArrayList;
import java.util.List;

import app.pinggushi.bjesc.com.baserecyclerview.adapter.MultiItemTypeAdapter;
import app.pinggushi.bjesc.com.baserecyclerview.adapter.RecycleViewDivider;
import butterknife.Bind;

/**
 * Created by yidong on 2017/6/22.
 */

public class DetectFragment extends BaseFragment implements MultiItemTypeAdapter.OnItemClickListener {
    @Bind(R.id.recyclerView)
    RecyclerView recyclerView;
    @Bind(R.id.tv_title)
    TextView titleTv;
    @Bind(R.id.iv_return)
    LinearLayout returnLin;
    private MainViewAdapter adapter;
    private List<ItemViewBean> list;
    private String [] titles = {"待检测车源","打回历史"};
    private int [] resID = {R.mipmap.await_detect_car,R.mipmap.return_car_source};
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        contentView = inflater.inflate(R.layout.layout_fragment, null);
        return super.onCreateView(inflater, container, savedInstanceState);
    }
    @Override
    public void initView() {
        returnLin.setVisibility(View.GONE);
        GridLayoutManager manager = new GridLayoutManager(getActivity(),3);
        recyclerView.setLayoutManager(manager);
        titleTv.setText(getResources().getText(R.string.detect));
    }

    @Override
    public void initData() {
        list = new ArrayList<>();
        for (int i = 0; i < titles.length; i++){
            ItemViewBean bean = new ItemViewBean();
            bean.setTitle(titles[i]);
            bean.setResID(resID[i]);
            list.add(bean);
        }
        adapter = new MainViewAdapter(getActivity(),R.layout.item_gridview,list);
        adapter.setOnItemClickListener(this);
        RecycleViewDivider divider = new RecycleViewDivider(getActivity(), RecycleViewDivider.GRID,3, R.color.colorEBEBEB);
        recyclerView.setAdapter(adapter);
        recyclerView.addItemDecoration(divider);
    }


    @Override
    public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
               switch (position){
                   case 0:
                       startActivity(new Intent(getActivity(),WaitCheckActivity.class));
                       break;
                   case 1:
                       startActivity(new Intent(getActivity(),RepulseHistoryActivity.class));
                       break;
               }
    }

    @Override
    public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
        return false;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
}
